<?php
/**
 * @category   Application_Extensions
 * @package    Talktangle Plugin 
 * @copyright  idragon Co., Ltd.
 * @license
 */
class Talktangle_Installer extends Engine_Package_Installer_Module {
	function onInstall() {
		$this->addTanglePage();
		parent::onInstall();
	}
protected function addTanglePage()
 {
 	$db = $this->getDb();
    $select = new Zend_Db_Select($db);

    // Check if it's already been placed
    $select = new Zend_Db_Select($db);
    $hasWidget = $select
      ->from('engine4_core_pages', new Zend_Db_Expr('TRUE'))
      ->where('name = ?', 'talktangle_index_index')
      ->limit(1)
      ->query()
      ->fetchColumn()
      ;

    // Add it
    if( empty($hasWidget) ) {

      $db->insert('engine4_core_pages', array(
        'name' => 'talktangle_index_index',
        'displayname' => 'Talktangle view ',
        'title' => '',
        'description' => '',
        'custom' => 0,
        'provides' => 'subject=event',
      ));
      $page_id = $db->lastInsertId('engine4_core_pages');

      //menu
       $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'top',
        'parent_content_id' => null,
        'order' => 1,
        'params' => '',
      ));
      $container_id = $db->lastInsertId('engine4_core_content');

      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'middle',
        'parent_content_id' => $container_id,
        'order' => 6,
        'params' => '',
      ));
      $middle_id = $db->lastInsertId('engine4_core_content');
      
      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'widget',
        'name' => 'talktangle.menu-top',
        'parent_content_id' => $middle_id,
        'order' => 3,
        'params' => '',
      ));
     
      
      // containers
      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'main',
        'parent_content_id' => null,
        'order' => 2,
        'params' => '',
      ));
      $container_id = $db->lastInsertId('engine4_core_content');

      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'middle',
        'parent_content_id' => $container_id,
        'order' => 6,
        'params' => '',
      ));
      $middle_id = $db->lastInsertId('engine4_core_content');

      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'left',
        'parent_content_id' => $container_id,
        'order' => 5,
        'params' => '',
      ));
      $left_id = $db->lastInsertId('engine4_core_content');
     
     $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'widget',
        'name' => 'talktangle.menu-left',
        'parent_content_id' => $left_id,
        'order' => 6,
        'params' => '',
      ));
        
      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'container',
        'name' => 'right',
        'parent_content_id' => $container_id,
        'order' => 5,
        'params' => '',
      ));
      $right_id = $db->lastInsertId('engine4_core_content');

      // middle column
      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'widget',
        'name' => 'talktangle.content',
        'parent_content_id' => $middle_id,
        'order' => 6,
        'params' => '{"max":"6"}',
      ));
      $tab_id = $db->lastInsertId('engine4_core_content');

      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type' => 'widget',
        'name' => 'taltangle.recent',
        'parent_content_id' => $right_id,
        'order' => 9,
        'params' => '',
      ));
     

      
    }
  
 }
}
?>